package cn.xgxd.web;

import cn.xgxd.pojo.Goods;
import cn.xgxd.result.Result;
import cn.xgxd.service.CartService;
import com.baomidou.mybatisplus.extension.api.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@CrossOrigin
@RequestMapping("/cart")
public class CartController {
    @Autowired
    CartService cartService;
    @PostMapping
    public Result addCart(@RequestBody Goods goods){
        return cartService.addCart(goods)?Result.success():Result.error("添加失败,请查看是否已添加");
    }
    @GetMapping
    public Result selectCart(){
        return Result.success(cartService.selectCart());
    }

    @GetMapping("/{id}")
    public Result deleteCart(@PathVariable ("id") String id){
        return cartService.deleteCart(id)?Result.success():Result.error("删除失败");
    }
}
